package com.fang.excel.controller;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class CallableExample {
    public static void main(String[] args) throws Exception {
        ExecutorService executor = Executors.newFixedThreadPool(2);

        Callable<String> callableTask = () -> {
            Thread.sleep(2000);
            return "任务执行完成";
        };

        Future<String> future = executor.submit(callableTask);

        // 可以在这里执行其他操作
        System.out.println("等待任务完成...");

        String result = future.get(); // 阻塞直到任务完成
        System.out.println("结果: " + result);

        executor.shutdown();
    }
}
